package com.veo.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CustomExceptionResolver implements HandlerExceptionResolver {
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        CustomException exception =  null;
        if (e instanceof CustomException){
            exception = (CustomException) e;
        }else {
            exception = new CustomException("未知错误请联系管理员");
        }
        ModelAndView mv = new ModelAndView();
        mv.addObject("message",exception.getMessage());
        mv.setViewName("error");
        return mv;
    }
}
